#include <iostream>
#include <vector>
using namespace std;

//***************************************** Question 1 ********************************************************
//Integer Min/Max functions

int findMinIntIndex(const vector<int>& input){
	if(input.size() < 1)	//in case the function is passed an empty set
		return -1;	

	int minIndex = 0; //first input is automatically the lowest number the function has seen because no other numbers have been seen at all 

	for(size_t i = 1; i < input.size(); i++){	//begine at SECOND input
		if(input[i] < input[minIndex]){
			minIndex = i;
		}
	}
	return minIndex;
}

int findMaxIntIndex(const vector<int>& input){
	if(input.size() < 1)	//in case the function is passed an empty set
		return -1;	

	int maxIndex = 0; //first input is automatically the lowest number the function has seen because no other numbers have been seen at all 

	for(size_t i = 1; i < input.size(); i++){	//begine at SECOND input
		if(input[i] > input[maxIndex]){
			maxIndex = i;
		}
	}
	return maxIndex;
}

//Stringacter Min/Max Functions
//NOTE: value is determined by the ASCII numerical value for these characters
//Please refer to ASCII table when checking the validity
int findMinCharIndex(const vector<char>& input){
	if(input.size() < 1)	//in case the function is passed an empty set
		return -1;	

	int minIndex = 0; //first input is automatically the lowest number the function has seen because no other numbers have been seen at all 

	for(size_t i = 1; i < input.size(); i++){	//begine at SECOND input
		if(input[i] < input[minIndex]){
			minIndex = i;
		}
	}
	return minIndex;
}

int findMaxCharIndex(const vector<char>& input){
	if(input.size() < 1)	//in case the function is passed an empty set
		return -1;	

	int maxIndex = 0; //first input is automatically the lowest number the function has seen because no other numbers have been seen at all 

	for(size_t i = 1; i < input.size(); i++){	//begine at SECOND input
		if(input[i] > input[maxIndex]){
			maxIndex = i;
		}
	}
	return maxIndex;
}

//String min/max function

int findMinStringIndex(const vector<string>& input){
	if(input.size() < 1)	//in case the function is passed an empty set
		return -1;	

	int minIndex = 0; //first input is automatically the lowest number the function has seen because no other numbers have been seen at all 

	for(size_t i = 1; i < input.size(); i++){	//begine at SECOND input
		if(input[i][0] < input[minIndex][0]){
			minIndex = i;
		}
	}
	return minIndex;
}

int findMaxStringIndex(const vector<string>& input){
	if(input.size() < 1)	//in case the function is passed an empty set
		return -1;	

	int maxIndex = 0; //first input is automatically the lowest number the function has seen because no other numbers have been seen at all 

	for(size_t i = 1; i < input.size(); i++){	//begine at SECOND input
		if(input[i][0] > input[maxIndex][0]){
			maxIndex = i;
		}
	}
	return maxIndex;
}

//***************************************** Question 2 ********************************************************

class Node{
public:
	Node(char data, Node* ptr) : data(data), next(ptr) {}
	char data;
	Node* next;
};


int main(){
	//Question 1
	cout << "Index = Value" << endl << endl;
	vector<int> v;
	v.push_back(1);
	v.push_back(3);
	v.push_back(4);
	v.push_back(7);
	v.push_back(4);
	v.push_back(0);
	

	for(size_t i = 0; i< v.size(); ++i){
		cout << v[i] << " ";
	}
	cout << endl;
	cout << "Min: " << findMinIntIndex(v) << " = " << v[findMinIntIndex(v)]  << endl;
	cout << "Max: " << findMaxIntIndex(v) << " = " << v[findMaxIntIndex(v)] <<  endl << endl;

	vector<char> chars;
	chars.push_back('z');
	chars.push_back('b');
	chars.push_back('a');
	chars.push_back('A');
	chars.push_back('q');
	chars.push_back('r');
	for(size_t i = 0; i< chars.size(); ++i){
		cout << chars[i] << " ";
	}
	cout << endl;
	cout << "Min: " <<findMinCharIndex(chars) << " = " << chars[findMinCharIndex(chars)] << endl;
	cout << "Max: " << findMaxCharIndex(chars) << " = " << chars[findMaxCharIndex(chars)] << endl << endl;

	vector<string> str;
	str.push_back("apples");
	str.push_back("bananas");
	str.push_back("kiwi");
	for(size_t i = 0; i< str.size(); ++i){
		cout << str[i] << " ";
	}
	cout << endl;
	cout << "Min: " <<findMinStringIndex(str) << " = " << str[findMinStringIndex(str)] << endl;
	cout << "Max: " << findMaxStringIndex(str) << " = " << str[findMaxStringIndex(str)] << endl << endl;

	//Question 2---------------------------------------------------------------------
	
	//make the Linked list 'B'->'D'->'E'
	Node* nodeptr = new Node('B', new Node('D', new Node('E', NULL)));
	//prepend 'A' to the list
	nodeptr = new Node('A', nodeptr);
	//add 'C' after 'B' and before 'D'
	Node* bPtr = nodeptr->next; 		//temporary pointer to B
	Node* cPtr = new Node('C', bPtr->next);	//C node now points to the rest of the list
	bPtr->next = cPtr;			//B now points to C
	//Print Mem locations
	Node* tmp = nodeptr;
	while(tmp != NULL){
		cout << tmp << " ";
		tmp = tmp->next;
	}
	cout << endl;
	//delete A
	Node* newHead = nodeptr->next;
	delete nodeptr;
	nodeptr = newHead;

	cout << endl;

	//Question 3---------------------------------------------------------------------

	int* intPtr = new int[5];

	*intPtr = 2;
	*(intPtr+1) = 3;
	*(intPtr+2) = 4;
	*(intPtr+3) = 5;
	
	//loop bumps everything forward opening the first space
	for(int i = 4; i > 0 ; --i){
		*(intPtr+i) = *(intPtr+i-1);
	}
	*intPtr = 1;

	for(int i = 0; i < 5; ++i){
		cout << (intPtr+i) << " ";
	}
	cout << endl;

	delete[] intPtr;
}


